package com.ych.modules.base.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.ych.SDK.alibaba.ossSDK.AliOssUtil;
import com.ych.modules.base.dbEntity.TJobReceiveEntity;
import com.ych.modules.base.dbEntity.TSysImgEntity;
import com.ych.modules.base.mapper.TJobReceiveMapper;
import com.ych.modules.base.service.ITJobReceiveService;
import com.ych.modules.base.service.ITSysImgService;
import com.ych.utils.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * Author: Usopp.tsui
 * Date: 2021/3/13
 * Time: 10:20
 * Description:
 */
@Service("ITJobReceiveService")
public class TJobReceiveServiceImpl extends ServiceImpl<TJobReceiveMapper, TJobReceiveEntity> implements ITJobReceiveService {
    @Autowired
    private AliOssUtil      aliOssUtil;
    @Autowired
    private ITSysImgService itSysImgService;

    @Override
    public void addStepImg(String id, Integer sequence, String imgUrl) {
        //第一个进来，清除原有图片
        if (sequence == 0) {
            //判断有无图片已经上传了的，有的话先删除掉
            Wrapper<TSysImgEntity> wrapper = new EntityWrapper<TSysImgEntity>()
                    .where("1=1")
                    .eq("img_type", "10008004")
                    .eq("business_id", id);
            itSysImgService.delete(wrapper);//先把已有的删除掉
        }
        TSysImgEntity imgEntity = new TSysImgEntity();
        imgEntity.setImgId(UUID.randomUUID());
        if ("-1".equals(imgUrl)) {//为-1则改步骤不需要图片，这里的地址给-1
            imgEntity.setImgUrl(imgUrl);
        } else {
            imgEntity.setImgUrl(aliOssUtil.getRelativePath(imgUrl));
        }
        imgEntity.setImgType("10008004");//完成领取任务步骤图片
        imgEntity.setBusinessId(id);
        imgEntity.setImgSequence(sequence);
        imgEntity.setCreate_time(new Date());
        itSysImgService.insert(imgEntity);
    }
}
